﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TypeRuleEdit.aspx.cs" Inherits="Sdepci.InfoCode.Web.CodeDesign.TypeRuleEdit" ValidateRequest="false" %>
<%@ Register src="../Includes/VerifyLoginState.ascx" tagname="VerifyLoginState" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>编码规则编辑</title>
    <link rel="stylesheet" type="text/css" href="../Css/Style.css" />
    <link rel="stylesheet" type="text/css" href="../Css/Backstage.css" />
    <script type="text/javascript" src="../Javascript/Common.js"></script>
    <script type="text/javascript">
    // 输入域检查
    function ValidateInput()
    {
        document.getElementById("RuleName").value = document.getElementById("RuleName").value.trim();
        if (document.getElementById("RuleName").value == "") {
            alert("规则名称不能为空！");
            document.getElementById("RuleName").focus();
            document.getElementById("RuleName").select();
            return false;
        }

        document.getElementById("Seq").value = document.getElementById("Seq").value.trim();
        if (!checkNaturalNumber(document.getElementById("Seq").value)) {
            alert("显示次序必须是正整数！");
            document.getElementById("Seq").focus();
            document.getElementById("Seq").select();
            return false;
        }

        if (!ValidateModule()) {
            return false;
        }

        return true;
    }

    function ValidateModule() {
    
        // 验证编码规则格式
        try {
            var moduleXml = null;
            var infocode = null;

            if (navigator.userAgent.indexOf("Firefox") > 0) {
                moduleXml = document.implementation.createDocument("text/xml", "", null);
            }
            else if (navigator.userAgent.indexOf("MSIE") > 0) {
                moduleXml = new ActiveXObject("Microsoft.XMLDOM");
                moduleXml.async = false;
            }

            if (document.getElementById("RuleModule").value.trim() == "") {
                moduleXml.loadXML("");
                infocode = moduleXml.createElement("infocode");
                moduleXml.appendChild(infocode);
            }
            else {
                moduleXml.loadXML(document.getElementById("RuleModule").value);
                infocode = moduleXml.getElementsByTagName("infocode")[0];
            }
            
            // 验证编码规则中是否只含有一个流水号
            var serial = 0;
            var regions = infocode.childNodes;
            for (var i = 0; i < regions.length; i++) {
                if (regions[i].getAttribute("type") == "serial") {
                    serial++;
                }
            }

            if (serial > 1) {
                alert("规则模型错误：只允许有一个顺序流水号类型的编码项！");
                return false;
            }
        }
        catch (e) {
            alert("规则模型XML格式错误：无法解析！");
            return false;
        }

        return true;
    }
    
    function OpenModule() {
        if (ValidateModule()) {
            var result = window.showModalDialog("TypeRuleModule.aspx", window, "dialogWidth:640px;dialogHeight:480px");
        }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <uc1:VerifyLoginState ID="VerifyLoginState1" runat="server" />
    <div id="container">
        <div id="editregion">
            <table style="width: 100%;">
                <caption><asp:Label ID="lblTitle" runat="server" Text="编码规则编辑"></asp:Label></caption>
                <tr>
                    <td class="label"><font color="#ff0000"> ※ </font>规则名称：</td>
                    <td class="input">
                        <asp:TextBox ID="RuleName" CssClass="text" MaxLength="20" runat="server"></asp:TextBox>
                    </td>
                    <td class="label"><font color="#ff0000"> ※ </font>显示次序：</td>
                    <td class="input">
                        <asp:TextBox ID="Seq" CssClass="text" MaxLength="4" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">中文描述：</td>
                    <td class="input" colspan="3">
                        <asp:TextBox ID="RuleDesc" CssClass="text" TextMode="MultiLine" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="label">规则模型：</td>
                    <td class="input" colspan="3">
                        <asp:TextBox ID="RuleModule" CssClass="text" Width="90%" Height="120px" TextMode="MultiLine" runat="server"></asp:TextBox>
                        <input type="button" class="button-open" onclick="javascript:OpenModule();" />
                    </td>
                </tr>
                <tr>
                    <td class="label">编码示例：</td>
                    <td class="input" colspan="3">
                        <asp:TextBox ID="RuleDemo" CssClass="text" MaxLength="50" runat="server"></asp:TextBox>
                    </td>
                </tr>
            </table>
        </div>
        <div id="buttonregion">
            <asp:Button ID="btnSave" CssClass="button" runat="server" Text="保存" UseSubmitBehavior="false" onclick="btnSave_Click" OnClientClick="javascript:if(!ValidateInput()) return false;" />
            <asp:Button ID="btnCancel" CssClass="button" runat="server" Text="取消" UseSubmitBehavior="false" onclick="btnCancel_Click" />
        </div>
        <div id="tipsregion">
            标有“<font color="#ff0000"> ※ </font>”符号的为必填项。<br />
        </div>
    </div>
    </form>
</body>
</html>
